﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using eVision.SharpSort;
using System.IO;
using System.Xml;

namespace UnitTesting
{
    [TestClass]
    class Program
    {
        #region Settings
        public static String path = @"C:\Documents and Settings\Axiom\Desktop\Query.xml";
        public static List<CodeMemberInfo> codeMembers = new List<CodeMemberInfo>(){
            new CodeMemberInfo()
            {
                AccessModifier = CodeMemberInfo.AccessModifierEnum.@public,
                EntityType = CodeMemberInfo.EntityTypeEnum.Method,
                IsStatic = false,
                Name = "Hello4",
                NumberOfParameters = 2,
                EntityVariableType = "eVision.SharePoint.V3",
                Code = 
@"public void Hello4(int a, int b)
{
    int a;
    int b;
}"
            },
            new CodeMemberInfo()
            {
                AccessModifier = CodeMemberInfo.AccessModifierEnum.@public,
                EntityType = CodeMemberInfo.EntityTypeEnum.Method,
                IsStatic = false,
                Name = "Hello4",
                NumberOfParameters = 3,
                EntityVariableType = "eVision.SharePoint.V3",
                Code = 
@"public void Hello4(int a, int b, int c)
{
    int a;
    int b;
}"
            },
            new CodeMemberInfo()
            {
                AccessModifier = CodeMemberInfo.AccessModifierEnum.@public,
                EntityType = CodeMemberInfo.EntityTypeEnum.Method,
                IsStatic = true,
                Name = "Helloaaaaaaa",
                NumberOfParameters = 2,
                EntityVariableType = "eVision.SharePoint.V3",
                Code = 
@"public static void Helloaaaaaaa(int a, int b)
{
    int a;
    int b;
}"
            },
            new CodeMemberInfo()
            {
                AccessModifier = CodeMemberInfo.AccessModifierEnum.@public,
                EntityType = CodeMemberInfo.EntityTypeEnum.Method,
                IsStatic = true,
                Name = "Helloaaaaaaa",
                NumberOfParameters = 3,
                EntityVariableType = "eVision.SharePoint.V3",
                Code = 
@"public static void Helloaaaaaaa(int a, int b, int c)
{
    int a;
    int b;
}"
            },
            new CodeMemberInfo()
            {
                AccessModifier = CodeMemberInfo.AccessModifierEnum.@public,
                EntityType = CodeMemberInfo.EntityTypeEnum.Method,
                IsStatic = true,
                Name = "Nah",
                NumberOfParameters = 3,
                EntityVariableType = "eVision.SharePoint.V3",
                Code = 
@"public static void Nah(int a, int b, int c)
{
    int a;
    int b;
}"
            },
            new CodeMemberInfo()
            {
                AccessModifier = CodeMemberInfo.AccessModifierEnum.@public,
                EntityType = CodeMemberInfo.EntityTypeEnum.Method,
                IsStatic = true,
                Name = "AkoMeOstavis",
                NumberOfParameters = 3,
                EntityVariableType = "eVision.SharePoint.V3",
                Code = 
@"public static void AkoMeOstavis(int a, int b, int c)
{
    int a;
    int b;
}"
            },
            new CodeMemberInfo()
            {
                AccessModifier = CodeMemberInfo.AccessModifierEnum.@public,
                EntityType = CodeMemberInfo.EntityTypeEnum.Field,
                IsStatic = true,
                Name = "a",
                NumberOfParameters = 0,
                EntityVariableType = "eVision.SharePoint.V3",
                Code = @"public static String a = """";"
            },
            new CodeMemberInfo()
            {
                AccessModifier = CodeMemberInfo.AccessModifierEnum.@public,
                EntityType = CodeMemberInfo.EntityTypeEnum.Field,
                IsStatic = true,
                Name = "b",
                NumberOfParameters = 0,
                EntityVariableType = "eVision.SharePoint.V3",
                Code = @"public static String b = """";"
            },
            new CodeMemberInfo()
            {
                AccessModifier = CodeMemberInfo.AccessModifierEnum.@public,
                EntityType = CodeMemberInfo.EntityTypeEnum.Field,
                IsStatic = true,
                Name = "bb",
                NumberOfParameters = 0,
                EntityVariableType = "eVision.SharePoint.V3",
                Code = @"public static String bb = """";"
            },
            new CodeMemberInfo()
            {
                AccessModifier = CodeMemberInfo.AccessModifierEnum.@public,
                EntityType = CodeMemberInfo.EntityTypeEnum.Field,
                IsStatic = false,
                Name = "staticbb",
                NumberOfParameters = 0,
                EntityVariableType = "eVision.SharePoint.V3",
                Code = @"public static String staticbb = """";"
            },
            new CodeMemberInfo()
            {
                AccessModifier = CodeMemberInfo.AccessModifierEnum.@public,
                EntityType = CodeMemberInfo.EntityTypeEnum.Field,
                IsStatic = false,
                Name = "statica",
                NumberOfParameters = 0,
                EntityVariableType = "eVision.SharePoint.V3",
                Code = @"public static String statica = """";"
            },
            };

        #endregion

        static void Maint(String[] args)
        {
            RegionDefinition region = Serializer.XmlDeserialize<RegionDefinition>(File.ReadAllText(path));
        }

        static void Main6(String[] args)
        {

            RegionDefinition region = Serializer.XmlDeserialize<RegionDefinition>(File.ReadAllText(path));

            foreach (CodeMemberInfo info in codeMembers)
            {
                Console.WriteLine(region.Where.Evaluate(info));
            }

            foreach (CodeMemberInfo info in region.Sort(codeMembers))
            {
                Console.WriteLine(info.SimpleFormat());
            }
            //ParseNode where = Serializer.XmlDeserialize<ParseNode>(File.ReadAllText());
            //where.Ands = new And[3];
            //File.WriteAllText(path + 2, Serializer.XmlSerialize<Where>(where));

        }
        static void Main(String[] args)
        {
            RegionDefinition region = Serializer.XmlDeserialize<RegionDefinition>(File.ReadAllText(path));

            ICollection<CodeMemberInfo> removedMembers = new List<CodeMemberInfo>();
            bool isEmpty;
            String code = region.GenerateCode(0, codeMembers, removedMembers, out isEmpty);

            Console.WriteLine(code);
            File.WriteAllText(path + "3", code);
            //ParseNode where = Serializer.XmlDeserialize<ParseNode>(File.ReadAllText());
            //where.Ands = new And[3];
            //File.WriteAllText(path + 2, Serializer.XmlSerialize<Where>(where));

        }
        static void Main2(string[] args)
        {
            //ParseNode where = null;
            XmlDocument doc = new XmlDocument();
            doc.Load(path);
            Where where = new Where(doc.DocumentElement);

            CodeMemberInfo codeMemberInfo = new CodeMemberInfo()
            {
                AccessModifier = CodeMemberInfo.AccessModifierEnum.@public,
                EntityType = CodeMemberInfo.EntityTypeEnum.Method,
                IsStatic = true,
                Name = "Hello4",
                NumberOfParameters = 4,
                EntityVariableType = "eVision.SharePoint.V3"
            };


            Console.WriteLine(where.Evaluate(codeMemberInfo));
            //ParseNode where = Serializer.XmlDeserialize<ParseNode>(File.ReadAllText());
            //where.Ands = new And[3];
            //File.WriteAllText(path + 2, Serializer.XmlSerialize<Where>(where));
        }
    }
}
